package com.nanhai.buddhist.college.module.collegebase.controller.admin.classroomfunction;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.nanhai.buddhist.college.framework.common.pojo.PageResult;
import com.nanhai.buddhist.college.framework.common.pojo.CommonResult;
import static com.nanhai.buddhist.college.framework.common.pojo.CommonResult.success;

import com.nanhai.buddhist.college.framework.excel.core.util.ExcelUtils;

import com.nanhai.buddhist.college.framework.operatelog.core.annotations.OperateLog;
import static com.nanhai.buddhist.college.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.nanhai.buddhist.college.module.collegebase.controller.admin.classroomfunction.vo.*;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.classroomfunction.ClassroomFunctionDO;
import com.nanhai.buddhist.college.module.collegebase.convert.classroomfunction.ClassroomFunctionConvert;
import com.nanhai.buddhist.college.module.collegebase.service.classroomfunction.ClassroomFunctionService;

@Api(tags = "管理后台 - 教室功能")
@RestController
@RequestMapping("/collegebase/classroom-function")
@Validated
public class ClassroomFunctionController {

    @Resource
    private ClassroomFunctionService classroomFunctionService;

    @PostMapping("/create")
    @ApiOperation("创建教室功能")
    public CommonResult<String> createClassroomFunction(@Valid @RequestBody ClassroomFunctionCreateReqVO createReqVO) {
        return success(classroomFunctionService.createClassroomFunction(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新教室功能")
    public CommonResult<Boolean> updateClassroomFunction(@Valid @RequestBody ClassroomFunctionUpdateReqVO updateReqVO) {
        classroomFunctionService.updateClassroomFunction(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除教室功能")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
    public CommonResult<Boolean> deleteClassroomFunction(@RequestParam("id") String id) {
        classroomFunctionService.deleteClassroomFunction(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得教室功能")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    public CommonResult<ClassroomFunctionRespVO> getClassroomFunction(@RequestParam("id") String id) {
        ClassroomFunctionDO classroomFunction = classroomFunctionService.getClassroomFunction(id);
        return success(ClassroomFunctionConvert.INSTANCE.convert(classroomFunction));
    }

    @GetMapping("/list")
    @ApiOperation("获得教室功能列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    public CommonResult<List<ClassroomFunctionRespVO>> getClassroomFunctionList(@RequestParam("ids") Collection<String> ids) {
        List<ClassroomFunctionDO> list = classroomFunctionService.getClassroomFunctionList(ids);
        return success(ClassroomFunctionConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得教室功能分页")
    public CommonResult<PageResult<ClassroomFunctionRespVO>> getClassroomFunctionPage(@Valid ClassroomFunctionPageReqVO pageVO) {
        PageResult<ClassroomFunctionDO> pageResult = classroomFunctionService.getClassroomFunctionPage(pageVO);
        return success(ClassroomFunctionConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出教室功能 Excel")
    @OperateLog(type = EXPORT)
    public void exportClassroomFunctionExcel(@Valid ClassroomFunctionExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<ClassroomFunctionDO> list = classroomFunctionService.getClassroomFunctionList(exportReqVO);
        // 导出 Excel
        List<ClassroomFunctionExcelVO> datas = ClassroomFunctionConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "教室功能.xls", "数据", ClassroomFunctionExcelVO.class, datas);
    }

}
